package org.extframework.ld.xml.base;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : Dong.Li
 * @created : 2013-1-17
 * @version : 1.0
 * @description :
 */
public class ExtParameter {

	private String name;
	private Map<String, Object> map = new HashMap<String, Object>();

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, Object> getMap() {
		return this.map;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}

	public String queryString() {
		StringBuffer paramBuffer = new StringBuffer();
		paramBuffer.append(" AND ");
		boolean isLike = false;

		String row = (String) getMap().get("row");
		row = row.replaceAll("_", ".");

		String condition = (String) getMap().get("condition");
		if (condition.equalsIgnoreCase("like"))
			isLike = true;
		else {
			isLike = false;
		}

		String param = (String) getMap().get("param");
		param = (param.equals("是")) ? "true" : param;
		param = (param.equals("否")) ? "false" : param;
		param = (param.equals("-")) ? "NULL" : param;
		if (isLike) {
			param = "%" + param + "%";
		}

		paramBuffer.append(row);
		paramBuffer.append(" ");
		paramBuffer.append(condition);
		paramBuffer.append(" ");
		if ((!(param.equals("NULL"))) && (!(param.equals("true")))
				&& (!(param.equals("false")))) {
			paramBuffer.append(" '");
		}

		paramBuffer.append(param);

		if ((!(param.equals("NULL"))) && (!(param.equals("true")))
				&& (!(param.equals("false")))) {
			paramBuffer.append("' ");
		}
		paramBuffer.append(" ");
		return paramBuffer.toString();
	}

}
